package com.da.web.dorm_look.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.da.common.Result;
import com.da.web.dorm_look.entity.DormLook;
import com.da.web.dorm_look.entity.LookParm;
import com.da.web.dorm_look.service.DormLookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author da
 * @time 2023/12/15 上午 11:34
 */
@RestController
@RequestMapping("/api/look")
public class DormLookController {
    @Autowired
    private DormLookService dormLookService;

    //新增
    @PostMapping
    public Result add(@RequestBody DormLook dormLook) {
        boolean save = dormLookService.save(dormLook);
        if (save) {
            return Result.success("新增成功");
        }
        return Result.error("新增失败");
    }

    //编辑
    @PutMapping
    public Result edit(@RequestBody DormLook dormLook) {
        boolean save = dormLookService.updateById(dormLook);
        if (save) {
            return Result.success("编辑成功");
        }
        return Result.error("编辑失败");
    }

    //删除
    @DeleteMapping("/{lookId}")
    public Result delete(@PathVariable("lookId") Long lookId) {
        boolean save = dormLookService.removeById(lookId);
        if (save) {
            return Result.success("删除成功");
        }
        return Result.error("删除失败");
    }

    //列表
    @GetMapping("/list")
    public Result getList(LookParm parm) {
        IPage<DormLook> list = dormLookService.pageList(parm);
        return Result.success("查询成功", list);
    }
}
